import fs from 'fs'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'node:url'

import minimist from 'minimist'

const __dirname = dirname(fileURLToPath(import.meta.url))

// 命令行参数
const argv = minimist(process.argv.slice(2), {
  default: {
    env: process.env.NODE_ENV || 'production',
    type: 'nvd',
  },
})

export const rootDir = resolve(__dirname, '..')
export const env = argv.env
export const type = argv.type
export const dataDir = resolve(rootDir, 'data', type)

// 确保目录存在
fs.mkdirSync(dataDir, { recursive: true })

console.log('运行任务', type)

export default {
  ...argv,
  rootDir,
  dataDir,
}
